// 选择题 表
const { STRING, INTEGER } = require('sequelize');
const chapter = require('../catelogue/chapter');

const sequelize = require('../sequelize');
const questiontype = require('./questiontype');

const question = sequelize.define('question', {
    title: {
        type: STRING,
        allowNull: false,
        comment: '题干'
    },
    options: {
        type: STRING,
        comment: '选择题选项'
    },
    answer: {
        type: STRING(255),
        allowNull: false,
        comment: '答案'
    },
    creator: {
        type: STRING,
        comment: '创建者'
    },
    createdate: {
        type: STRING(40),
        comment: '创建时间'
    },
    updator: {
        type: STRING,
        comment: '修改者'
    },
    updated: {
        type: STRING(40),
        comment: '修改时间'
    },
    chapter_id: {
        type: INTEGER(36),
        comment: '章节'
    },
    difficulty: {
        type: STRING(4),
        comment: '难易程度 （简单，容易，困难）'
    },
    usage: {
        type: STRING,
        comment: '使用量'
    },
    type_id: {
        type: INTEGER,
        comment: '题型'
    },
    analysis: {
        type:STRING,
        comment:'题解析'
    },
    catalouge_id: {
        type: INTEGER(36),
        comment: '科目'

    }
}, { timestamps: false, underscored: true });


question.associate = () => {
    question.belongsTo(chapter, {
        foreignKey: 'chapter_id',
        targetKey: 'id'
    });
    question.belongsTo(questiontype, {
        foreignKey: 'type_id',
        targetKey: 'id'
    });
};


module.exports = question;